#include <stdio.h>
#include <stdlib.h>
#include <csp_spu.h>
#include <csp_debug.h>

#define SUM 8385

int fact_cs(int number) {
	int res = 0;
	/* 1 .. 129 */
	int i1=1; int i2=2; int i3=3; int i4=4; int i5=5; int i6=6; 
	int i7=7; int i8=8; int i9=9; int i10=10; int i11=11; int i12=12; 
	int i13=13; int i14=14; int i15=15; int i16=16; int i17=17; int i18=18; 
	int i19=19; int i20=20; int i21=21; int i22=22; int i23=23; int i24=24; 
	int i25=25; int i26=26; int i27=27; int i28=28; int i29=29; int i30=30; 
	int i31=31; int i32=32; int i33=33; int i34=34; int i35=35; int i36=36; 
	int i37=37; int i38=38; int i39=39; int i40=40; int i41=41; int i42=42; 
	int i43=43; int i44=44; int i45=45; int i46=46; int i47=47; int i48=48; 
	int i49=49; int i50=50; int i51=51; int i52=52; int i53=53; int i54=54; 
	int i55=55; int i56=56; int i57=57; int i58=58; int i59=59; int i60=60; 
	int i61=61; int i62=62; int i63=63; int i64=64; int i65=65; int i66=66; 
	int i67=67; int i68=68; int i69=69; int i70=70; int i71=71; int i72=72; 
	int i73=73; int i74=74; int i75=75; int i76=76; int i77=77; int i78=78; 
	int i79=79; int i80=80; int i81=81; int i82=82; int i83=83; int i84=84;
	int i85=85; int i86=86; int i87=87; int i88=88; int i89=89; int i90=90; 
	int i91=91; int i92=92; int i93=93; int i94=94; int i95=95; int i96=96; 
	int i97=97; int i98=98; int i99=99; int i100=100; int i101=101; 
	int i102=102; int i103=103; int i104=104; int i105=105; int i106=106; 
	int i107=107; int i108=108; int i109=109; int i110=110; int i111=111; 
	int i112=112; int i113=113; int i114=114; int i115=115; int i116=116; 
	int i117=117; int i118=118; int i119=119; int i120=120; int i121=121; 
	int i122=122; int i123=123; int i124=124; int i125=125; int i126=126; 
	int i127=127; int i128=128; int i129=129; 



	csp_yield();

	/* 1+2+3+..+129 = 8385 */
	res = 
	i1+ i2+ i3+ i4+ i5+ i6+ i7+ i8+ i9+ i10+ i11+ i12+ i13+ i14+ i15+ i16+ 
	i17+ i18+ i19+ i20+ i21+ i22+ i23+ i24+ i25+ i26+ i27+ i28+ i29+ i30+ 
	i31+ i32+ i33+ i34+ i35+ i36+ i37+ i38+ i39+ i40+ i41+ i42+ i43+ i44+ 
	i45+ i46+ i47+ i48+ i49+ i50+ i51+ i52+ i53+ i54+ i55+ i56+ i57+ i58+ 
	i59+ i60+ i61+ i62+ i63+ i64+ i65+ i66+ i67+ i68+ i69+ i70+ i71+ i72+ 
	i73+ i74+ i75+ i76+ i77+ i78+ i79+ i80+ i81+ i82+ i83+ i84+ i85+ i86+ 
	i87+ i88+ i89+ i90+ i91+ i92+ i93+ i94+ i95+ i96+ i97+ i98+ i99+ i100+ 
	i101+ i102+ i103+ i104+ i105+ i106+ i107+ i108+ i109+ i110+ i111+ 
	i112+ i113+ i114+ i115+ i116+ i117+ i118+ i119+ i120+ i121+ i122+ 
	i123+ i124+ i125+ i126+ i127+ i128+ i129;


	ASSERT( (res + number) == (SUM + number)  );
	ASSERT( (res + number + 1) != (SUM + number)  );

	if(number == 0){
		return 1;
	}
	PRINTF_FOR_TESTING("Recursion: %i\n", number);
	return number * fact_cs(number - 1);
}
int Run(){
	PRINTF_FOR_TESTING("fact_yield_calleesaves_task running.\n");

	int res120 = fact_cs(5);

	ASSERT(120 == res120);	
	ASSERT(121 != res120);	

	PRINTF_FOR_TESTING("fact_yield_calleesaves_task terminated 120=%i.\n", res120);
	return res120;
}

